package framework.panes;

import framework.editor.UsuarioEditor;
import framework.editor.ProdutoEditor;
import framework.config.Utilities;
import framework.data.Produto;
import framework.data.Usuario;
import framework.db.ProdutoManager;
import framework.db.UsuarioManager;
import framework.parts.CidadeTablePane;
import framework.parts.QuartoTablePane;
import framework.parts.ClienteTablePane;
import framework.parts.GrupoQuartoTablePane;
import framework.parts.RelatoriosPane;
import framework.parts.ReservaQuartoTablePane;
import java.awt.CardLayout;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PrincipalPane.java
 *
 * Created on May 5, 2011, 9:56:31 PM
 */
/**
 *
 * @author usuario
 */
public class PrincipalPane extends javax.swing.JFrame
{
    private static final String CLIENTE_PANE = "clientePane";
    private static final String CIDADE_PANE = "cidadePane";
    private static final String PRODUTO_PANE = "produtoPane";
    private static final String RESERVA_PANE = "reservaPane";
    private static final String RESERVA_QUARTO_PANE = "reservaQuartoPane";
    private static final String QUARTO_PANE = "quartoPane";
    private static final String GRUPO_QUARTO_PANE = "grupoQuartoPane";
    private static final String RELATORIOS_PANE = "relatoriosPane";
    
    private ClienteTablePane clienteTablePane = new ClienteTablePane();
    private CidadeTablePane cidadeTablePane = new CidadeTablePane();
//    private UsuarioTablePane usuarioTablePane = new UsuarioTablePane();
//    private ProdutoTablePane produtoTablePane = new ProdutoTablePane();
    private ReservaQuartoTablePane reservaQuartoTablePane = new ReservaQuartoTablePane();
    private QuartoTablePane quartoTablePane = new QuartoTablePane();
    private GrupoQuartoTablePane grupoQuartoTablePane = new GrupoQuartoTablePane();
    private RelatoriosPane relatoriosPane = new RelatoriosPane();

    /** Creates new form PrincipalPane */
    public PrincipalPane()
    {
        initComponents ();
        
        jPanel1.add( clienteTablePane, CLIENTE_PANE );
        jPanel1.add( cidadeTablePane, CIDADE_PANE );
//        jPanel1.add( usuarioTablePane, USUARIO_PANE );
//        jPanel1.add( produtoTablePane, PRODUTO_PANE );
        jPanel1.add( reservaQuartoTablePane, RESERVA_QUARTO_PANE );
        jPanel1.add( quartoTablePane, QUARTO_PANE );
        jPanel1.add( grupoQuartoTablePane, GRUPO_QUARTO_PANE );
        jPanel1.add( relatoriosPane, RELATORIOS_PANE );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jButton8 = new javax.swing.JButton();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        jButton1.setText("Clientes");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(15, 15, 5, 5);
        getContentPane().add(jButton1, gridBagConstraints);

        jButton2.setText("Cidades");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(15, 0, 5, 5);
        getContentPane().add(jButton2, gridBagConstraints);

        jButton3.setText("Usuarios");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(15, 0, 5, 5);
        getContentPane().add(jButton3, gridBagConstraints);

        jButton4.setText("Produtos");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(15, 0, 5, 5);
        getContentPane().add(jButton4, gridBagConstraints);

        jButton5.setText("Reservas");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(15, 0, 5, 5);
        getContentPane().add(jButton5, gridBagConstraints);

        jButton6.setText("Quarto");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(15, 0, 5, 5);
        getContentPane().add(jButton6, gridBagConstraints);

        jButton7.setText("Grupo Quarto");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(15, 0, 5, 5);
        getContentPane().add(jButton7, gridBagConstraints);

        jPanel1.setLayout(new java.awt.CardLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 8;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 15, 15, 15);
        getContentPane().add(jPanel1, gridBagConstraints);

        jButton8.setText("Relatorios");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 7;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(15, 0, 5, 15);
        getContentPane().add(jButton8, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
        CardLayout cardLayout = (CardLayout) jPanel1.getLayout();
        
        clienteTablePane.refreshContent();
        cardLayout.show( jPanel1, CLIENTE_PANE );
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton6ActionPerformed
    {//GEN-HEADEREND:event_jButton6ActionPerformed
        CardLayout cardLayout = (CardLayout) jPanel1.getLayout();
        
        quartoTablePane.refreshContent();
        cardLayout.show( jPanel1, QUARTO_PANE );
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
    {//GEN-HEADEREND:event_jButton2ActionPerformed
        CardLayout cardLayout = (CardLayout) jPanel1.getLayout();
        
        cidadeTablePane.refreshContent();
        cardLayout.show( jPanel1, CIDADE_PANE );
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton7ActionPerformed
    {//GEN-HEADEREND:event_jButton7ActionPerformed
        CardLayout cardLayout = (CardLayout) jPanel1.getLayout();
        
        grupoQuartoTablePane.refreshContent();
        cardLayout.show( jPanel1, GRUPO_QUARTO_PANE );
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton4ActionPerformed
    {//GEN-HEADEREND:event_jButton4ActionPerformed
        Produto p = new Produto();
        
        try
        {
            if ( ProdutoEditor.edit( this, p ) )
            {
                ProdutoManager.getInstance().addProduto( p );
            }
        }
        
        catch ( Exception e )
        {
            Utilities.handleException( e );
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton3ActionPerformed
    {//GEN-HEADEREND:event_jButton3ActionPerformed
        Usuario u = new Usuario();
        
        try
        {
            if ( UsuarioEditor.edit( this, u ) )
            {
                UsuarioManager.getInstance().addUsuario( u );
            }
        }
        
        catch ( Exception e )
        {
            Utilities.handleException( e );
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        CardLayout cardLayout = (CardLayout) jPanel1.getLayout();
        
        reservaQuartoTablePane.refreshContent();
        cardLayout.show( jPanel1, RESERVA_QUARTO_PANE );
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton8ActionPerformed
    {//GEN-HEADEREND:event_jButton8ActionPerformed
        CardLayout cardLayout = (CardLayout) jPanel1.getLayout();
        
        cardLayout.show( jPanel1, RELATORIOS_PANE );
    }//GEN-LAST:event_jButton8ActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
